﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Stu_sys.Entity;

namespace Stu_sys.Controllers
{
    public class LoginController : Controller
    {
        private readonly MysqlContext _context;
        public LoginController(MysqlContext mysqlContext) 
        {
            _context=mysqlContext;
        }
        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public  IActionResult Login(User user)
        {
            var first = _context.Users.Where(u => u.UserName==user.UserName&&u.Password==user.Password).FirstOrDefault();
            return Json(first);
        }

        [HttpGet]
        public IActionResult AddUser() 
        { 
            User user = new User() { 
                RealName="zhangsan",
                UserName="admin",
                Password="123456"
            };
           _context.Users.Add(user);
           var res= _context.SaveChanges();
            return Json(res);
        }
    }
}
